package operation;

import staff.Staff;
import staff.StaffList;
import java.util.Scanner;
public class DelOperation implements IOperation{
    @Override
    public Staff work(StaffList staffList) {
        System.out.println("员工基本信息删除");
        System.out.println("输入要删除的名字");
        Scanner sc = new Scanner(System.in);
        String staff_name = sc.nextLine();
        int size = staffList.getUsedSize();
        int index = 0;
        int i = 0;
        for (; i <size ; i++) {
            Staff curStaff = staffList.getStaffs(i);
            if(curStaff.getStaff_name().equals(staff_name)){
                index = i;
                break;
            }
        }
        if(i==size){
            System.out.println("无该员工！删除失败！");
            return null;
        }
        for (int j = index; j <size-1 ; j++) {
            Staff staff = staffList.getStaffs(j+1);
            staffList.setStaffs(j,staff);
        }
        staffList.setUsedSize(size-1);
        System.out.println("已删除成功！");
        return null;
    }
}
